<?php
//测试控制器类
class IndexControl extends Control{
	

    public function index(){
    	// p($_SESSION);
    	// echo substr(md5(mt_rand(1,100)),0,8);
    	// echo md5('admin'.'eccbc87e');
      $this->display('admin.php');
    }


    public function authCode(){
		$code = new code();
        $code->show();
	}
	public function code(){
		$code=strtolower($_POST['code']);
		if($code==strtolower($_SESSION['code'])){
			echo 1;
		}else{ 
			echo 0;
		}
		exit;
	}
	//后台登陆验证
	public function authReg(){
		$admin=strtolower(Q('aname'));
		$password=Q('password');
		if(IS_POST){
			if(M('admin')->find(array('aname'=>$admin))){
				$sql="SELECT * FROM hd_g_admin AS a JOIN hd_g_rloe AS r JOIN hd_g_admin_rloe AS ar ON 
				a.admin_id=ar.admin_id AND r.rid=ar.rid WHERE aname='{$admin}'";
				$data=M()->query($sql);
				if($data[0]['password']!=md5($password.$data[0]['code'])){
					$this->error('密码输入错误');
				}
				unset($data[0]['password']);
				unset($data[0]['code']);
				$_SESSION=array_merge($_SESSION,$data[0]);
				$this->success('登录成功','into');
			}else{
				$this->error('用户名输入错误');
			}
		}else{
			$this->display();
		}
		// if(M('admin')->find(array('aname'=>$admin))){
		// 	if(M('admin')->find(array('password'=>$password))){
		// 		$_SESSION['username']=$admin;
		// 		$this->success('登录成功','into');
		// 	}else{
		// 		$this->error('密码输入错误');
		// 	}
		// }else{
		// 	$this->error('用户名输入错误');
		// }
	}
	public function into(){

		$this->display('index.php');
	}

}
?>